﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Subgurim.Controles;
using System.Configuration;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Add basic controls to the map
        GMap1.Add(new GControl(GControl.preBuilt.GOverviewMapControl)); //Overview map control
        GMap1.Add(new GControl(GControl.preBuilt.LargeMapControl)); //Control over large map
        GMap1.Add(new GControl(GControl.preBuilt.MapTypeControl, 
            new GControlPosition(GControlPosition.position.Top_Right))); //Control for user to choose map type

        //Set initial location to Hanoi
        var location = new Subgurim.Controles.GLatLng(21.0278, 105.8523);
    }

    //Search location using GMap service
    protected void btnShowMap_Click(object sender, EventArgs e)
    {
        //Combine full address from Street, City and Country fields
        string address = txtKeyword.Text;

        //Get the API key from web.config file
        string skey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];

        //Create a new instance of GeoCode object from Gmap API
        GeoCode geocode;

        //Request location from the server using input keyword
        geocode = GMap1.getGeoCodeRequest(address);

        //Get Location at the latitude and longitude acquired from the Placemark coordinates which the server sends
        var glatlng = new Subgurim.Controles.GLatLng(geocode.Placemark.coordinates.lat, geocode.Placemark.coordinates.lng);

        //Add marker
        var oMarker = new Subgurim.Controles.GMarker(glatlng);
        GMap1.Add(oMarker);

        //Set the screen to center for hybrid map
        GMap1.setCenter(glatlng, 10, Subgurim.Controles.GMapType.GTypes.Hybrid);
        GInfoWindow window = new GInfoWindow(oMarker, "<center><b>" + address + "</b></center>", true);
        GMap1.Add(window);

    }
}